package cn.fl.quato.controller;

import java.text.DecimalFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.mfr.web.vo.MfrRlPsnVO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.quato.condition.QuatoBscInfoQC;
import cn.fl.quato.dto.QuatoBscInfoDTO;
import cn.fl.quato.dto.QuatoChangeHistoryDTO;
import cn.fl.quato.service.IQuatoBscInfoService;
import cn.fl.quato.vo.QuatoBscInfoVO;
import cn.fl.quato.vo.QuatoChangeHistoryVO;
import cn.fl.quato.vo.QuatoPrjTypChangeHistoryVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import com.alibaba.fastjson.JSON;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;

/**
 * @Description: 资管额度管理基础表 控制层
 */
@Controller
@RequestMapping("/quato/quatoBscInfo")
public class QuatoBscInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(QuatoBscInfoController.class);

	/**
	 * QuatoBscInfo 服务层BEAN
	 */
	@Autowired
	private IQuatoBscInfoService quatoBscInfoService;
	@Autowired
	private IFriBaseInfoService friBaseInfoService;
	@Autowired
	private ICstBscInfoService cstBscInfoService;
	@Autowired
	private IPrjBscInfoService prjBscInfoService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		ModelAndView view = new ModelAndView("quato/quatoBscInfo/quatoBscInfoList");
		String id = request.getParameter("id");
		view.addObject("id",id);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到新增修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAddPage", "加载新增.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		ModelAndView view = new ModelAndView("quato/quatoBscInfo/quatoBscInfoAdd");
		String id = request.getParameter("id");
		//资管id
		view.addObject("id",id);
		//事业部
		List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
		view.addObject("buOrgCdList", JSONArray.fromObject(orgList));
		//项目类型
		List<KeyValueVO> prjTypCdList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_PRJ_TYPE_CD,CurrentThreadContext.getCurrentSysCd(), "0000");
		view.addObject("orgList",orgList);
		view.addObject("prjTypCdList", JSONArray.fromObject(prjTypCdList));
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAddPage", "加载新增.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改额度页面
	 */
	@RequestMapping(value = "/toModifyQuatoPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyQuatoPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toModifyQuatoPage", "加载修改页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("quato/quatoBscInfo/modifyQuatoAmt");
		view.addObject("id", id);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toModifyQuatoPage", "加载修改.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改项目类型页面
	 */
	@RequestMapping(value = "/toModifyPrjTypCdPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyTypCdPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toModifyPrjTypCdPage", "加载修改页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("quato/quatoBscInfo/modifyPrjTypCd");
		view.addObject("id", id);
		QuatoBscInfoVO quatoBscInfoVO = quatoBscInfoService.selectQuatoBscInfoById(Long.valueOf(id),CurrentThreadContext.getCurrentSysCd());
		view.addObject("quatoBscInfoVO", net.sf.json.JSONObject.fromObject(quatoBscInfoVO));
		view.addObject("quatoBscInfoJSON", JSON.toJSONString(quatoBscInfoVO));
		List<KeyValueVO> prjTypCdList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_PRJ_TYPE_CD,CurrentThreadContext.getCurrentSysCd(), "0000");
		view.addObject("prjTypCdList",JSONArray.fromObject(prjTypCdList));
		List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
		view.addObject("buOrgCdList", JSONArray.fromObject(orgList));
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toModifyPrjTypCdPage", "加载修改.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("quato/quatoBscInfo/quatoBscInfoDetail");
		view.addObject("id", id);
		QuatoBscInfoVO quatoBscInfoVO = quatoBscInfoService.selectQuatoBscInfoById(Long.valueOf(id),CurrentThreadContext.getCurrentSysCd());
		view.addObject("quatoBscInfoVO", quatoBscInfoVO);
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String id = request.getParameter("id");
		//String searchName = request.getParameter("demo.name");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		QuatoBscInfoQC qc = new QuatoBscInfoQC();
		/*if (StringUtils.isNotEmpty(searchName)) {
		}*/
		FriBaseInfoVO friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd());
		if(friBaseInfoVO == null){
			DataResultVO result = new DataResultVO();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("机构不存在!");
			return result;
		}
		qc.setInsCode(friBaseInfoVO.getInsCode());
		page.setCondition(qc);

		Pager pager = this.quatoBscInfoService.searchListPage(page,CurrentThreadContext.getFlServiceSysCd());
		List<QuatoBscInfoVO> list = (List<QuatoBscInfoVO>) pager.getResultList();
		for (QuatoBscInfoVO quatoBscInfoVO : list) {
			quatoBscInfoVO.setAuditPassQuato(DecimalUtils.round(quatoBscInfoVO.getAuditPassQuato(),4));
			quatoBscInfoVO.setLoanQuato(DecimalUtils.round(quatoBscInfoVO.getLoanQuato(),4));
			quatoBscInfoVO.setRemainQuato(DecimalUtils.round(quatoBscInfoVO.getRemainQuato(),4));
		}
		ListPageVO<QuatoBscInfoVO> listPage = new ListPageVO<QuatoBscInfoVO>(list, pager.getTotalCount());
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "add", "新增额度管理数据.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		QuatoBscInfoVO entity = null;
		try {
			entity = getRequestParams(request);
			Long resultId = this.quatoBscInfoService.add(entity);
			result.setData(resultId);
			BaseLogUtils.info(logger, "add", "新增资管限额数据.[id="+resultId+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增资管限额对象失败", CurrentThreadContext.getCurrentUserName(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "add", "新增资管限额对象失败", CurrentThreadContext.getCurrentUserName(), ex);
		}
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "add", "新增对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		
		return result;
	}

	private QuatoBscInfoVO getRequestParams(HttpServletRequest request) {
		QuatoBscInfoVO quatoBscInfoVO = new QuatoBscInfoVO();
		String id = request.getParameter("id");
		String buOrgCd = request.getParameter("buOrgCd");
		String prjTypCd = request.getParameter("prjTypCd");
		String quatoAmt = request.getParameter("quatoAmt");
		if(StringUtils.isBlank(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"机构id为空!");
		}
		if(StringUtils.isBlank(buOrgCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择事业部!");
		}
		if(StringUtils.isBlank(prjTypCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择项目类型!");
		}
		if(StringUtils.isBlank(quatoAmt)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请输入额度!");
		}
		if(!quatoAmt.matches("-?[0-9]+(\\.[0-9]+)?")){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"额度必须为数字!");
		}
		//查询机构编码信息
		FriBaseInfoVO friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd());
		if(friBaseInfoVO == null){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"机构不存在!");
		}
		//根据金融机构编码、事业部、项目类型判断是否存在，存在的话提示
		//
		List<QuatoBscInfoVO> quatoBscInfoVOList = quatoBscInfoService.isExistSameInfo(null,friBaseInfoVO.getInsCode(),buOrgCd,prjTypCd);
		if(quatoBscInfoVOList.size() > 0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"该事业部、项目类型下配置信息已经存在，请重新配置!");
		}
		quatoBscInfoVO.setInsCode(friBaseInfoVO.getInsCode());
		quatoBscInfoVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		quatoBscInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		quatoBscInfoVO.setPrjTypCd(prjTypCd);
		quatoBscInfoVO.setBuOrgCd(buOrgCd);
		quatoBscInfoVO.setRemainQuato(Double.valueOf(quatoAmt));
		return quatoBscInfoVO;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modifyQuato.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyQuato(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		String changeType = request.getParameter("changeType");
		String changeAmount = request.getParameter("changeAmount");
		String remark = request.getParameter("remark");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据不存在!");
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		QuatoChangeHistoryVO entity = null;
		try {
			if(StringUtils.isBlank(changeType)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择变更类型!");
			}
			if(StringUtils.isBlank(changeAmount)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请填写变更金额!");
			}
			if(!changeAmount.matches("-?[0-9]+(\\.[0-9]+)?")){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"变更金额必须为数字！!");
			}
			if(StringUtils.isBlank(remark)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请填写备注!");
			}

			entity = new QuatoChangeHistoryVO();
			entity.setQuatoId(Long.valueOf(id));
			entity.setChangeType(Integer.valueOf(changeType));
			entity.setChangeAmount(Double.valueOf(changeAmount));
			entity.setRemark(remark);
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			//entity.setName(name);
			boolean success = this.quatoBscInfoService.modifyQuato(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败!");
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modifyPrjTypCd.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyPrjTypCd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String id = request.getParameter("id");
		String prjTypCd = request.getParameter("prjTypCd");
		String afterPrjTypCdNm = request.getParameter("afterPrjTypCdNm");
		String prjTypCdNm = request.getParameter("prjTypCdNm");
		String buOrgCd = request.getParameter("buOrgCd");
		String buOrgCdNm = request.getParameter("buOrgCdNm");
		String afterBuOrgCdNm = request.getParameter("afterBuOrgCdNm");
		String remark = request.getParameter("remark");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		QuatoBscInfoVO quatoBscInfoVO = quatoBscInfoService.selectQuatoBscInfoById(Long.valueOf(id),CurrentThreadContext.getCurrentSysCd());
		if(quatoBscInfoVO == null){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据不存在!");
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		QuatoPrjTypChangeHistoryVO entity = null;
		try {
			List<QuatoBscInfoVO> quatoBscInfoVOList = quatoBscInfoService.isExistSameInfo(Long.valueOf(id),quatoBscInfoVO.getInsCode(),buOrgCd,prjTypCd);
			if(quatoBscInfoVOList.size() > 0){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"该事业部、项目类型下配置信息已经存在，请重新配置!");
			}
			if(StringUtils.isBlank(buOrgCd)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择事业部!");
			}
			if(StringUtils.isBlank(prjTypCd)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择项目类型!");
			}
			if(StringUtils.isBlank(remark)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请填写备注!");
			}
			entity = new QuatoPrjTypChangeHistoryVO();
			entity.setQuatoId(Long.valueOf(id));
			//entity.setName(name);
			entity.setBeforeTypCdNames(prjTypCdNm);
			entity.setAfterTypCds(prjTypCd);
			entity.setAfterTypCdNames(afterPrjTypCdNm);
			entity.setBeforeBuOrgCdNames(buOrgCdNm);
			entity.setAfterBuOrgCds(buOrgCd);
			entity.setAfterBuOrgCdNames(afterBuOrgCdNm);
			entity.setRemark(remark);
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			boolean success = this.quatoBscInfoService.modifyPrjTypCd(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败!");
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "remove", "移除对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			return result;
		}
		try {
			this.quatoBscInfoService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "remove", "移除对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "remove", "移除对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "remove", "移除对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			QuatoBscInfoVO vo = quatoBscInfoService.selectQuatoBscInfoById(Long.valueOf(id),CurrentThreadContext.getCurrentSysCd());
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 查询变更历史记录
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getQuatoChangeHistory.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getQuatoChangeHistory(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getQuatoChangeHistory", "根据主键获取对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.error(logger, "getQuatoChangeHistory", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}

		try {
			List<QuatoChangeHistoryVO> vo = this.quatoBscInfoService.getQuatoChangeHistory(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getQuatoChangeHistory", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getQuatoChangeHistory", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			ListPageVO <QuatoChangeHistoryVO> listPage = new ListPageVO<QuatoChangeHistoryVO>(vo, vo.size());
			return listPage;
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getQuatoChangeHistory", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getQuatoChangeHistory", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 得到一条记录
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getQuatoPrjTypCdChangeHistory.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getQuatoPrjTypCdChangeHistory(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getQuatoPrjTypCdChangeHistory", "根据额度id获取项目类型变更对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("额度id不能为空!");
			BaseLogUtils.error(logger, "getQuatoPrjTypCdChangeHistory", "获取数据,额度id不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}

		try {
			List<QuatoPrjTypChangeHistoryVO> vo = this.quatoBscInfoService.getQuatoPrjTypCdChangeHistory(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getQuatoPrjTypCdChangeHistory", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			ListPageVO <QuatoPrjTypChangeHistoryVO> listPage = new ListPageVO<QuatoPrjTypChangeHistoryVO>(vo, vo.size());
			BaseLogUtils.info(logger, "getQuatoPrjTypCdChangeHistory", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return listPage;
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getQuatoPrjTypCdChangeHistory", "根据额度id获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getQuatoPrjTypCdChangeHistory", "根据额度id获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getQuatoPrjTypCdChangeHistory", "根据额度id获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}
}

